package httpClient;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class ByteUtil {
	
	 /**
     * 把一个文件转化为byte字节数组。
     *
     * @return
     */
    public static byte[] fileConvertToByteArray(File file) {
        byte[] data = null;
        FileInputStream fis = null;
        ByteArrayOutputStream baos = null;
        try {
        	fis = new FileInputStream(file);
        	baos = new ByteArrayOutputStream();
            int len;
            byte[] buffer = new byte[1024];
            while ((len = fis.read(buffer)) != -1) {
                baos.write(buffer, 0, len);
            }
 
            data = baos.toByteArray();
 

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
				fis.close();
				baos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
            
		}
 
        return data;
    }
}
